-------------------------------------------------------------------------------
-- Title      : VGA Display Module for lines of text
-- Project    : 
-------------------------------------------------------------------------------
-- File       : vgaLineDisplay.vhd
-- Author     : Paul W
-- Company    : 
-- Created    : 2012-12-04
-- Last update: 2012-12-12
-- Platform   : 
-- Standard   : VHDL'93
-------------------------------------------------------------------------------
-- Description: Preset lines of text for displaying user specified information.
--              
--              We use the 640x480 mode, yielding 80 columns by 60 rows of
--              text; however, part of this is used for waveform display.
-------------------------------------------------------------------------------
-- Copyright (c) 2012 
-------------------------------------------------------------------------------
-- Revisions  :
-- Date        Version  Author  Description
-- 2012-12-04  1.0      paul	Created
-------------------------------------------------------------------------------

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

library components;
use components.functions.all;
use components.txt_util.all;

entity vgaLineDisplay is

  generic (
    TEXT_COLOR : std_logic_vector(7 downto 0) := "11111111"
    );
  
  port (
    in_clk         : in  std_logic;
    in_clk25       : in  std_logic;
    in_clk40       : in  std_logic;
    in_rst         : in  std_logic;
    in_mhz         : in  natural;       -- 0 to 3000 or so
    in_khz         : in  natural;       -- 0 to 999
    in_radioOnOff  : in  std_logic;     -- 0=Off    1=On
    in_radioVol    : in  integer;       -- 0 to 99
    in_radioDemod  : in  std_logic;     -- 0=AM     1=FM
    in_radioOutput : in  std_logic;     -- 0=Phones 1=IF
    in_radioBws    : in  natural;
    in_audioData   : in  std_logic_vector(7 downto 0);
    in_audioDataEn : in  std_logic;
    in_backColor   : in  std_logic_vector(7 downto 0);
    out_vgaRed     : out std_logic_vector(2 downto 0);
    out_vgaGreen   : out std_logic_vector(2 downto 0);
    out_vgaBlue    : out std_logic_vector(1 downto 0);
    out_Hsync      : out std_logic;
    out_Vsync      : out std_logic
    );

end entity vgaLineDisplay;

architecture rtl of vgaLineDisplay is

  constant PAL         : integer := 640;  --Pixels/Active Line (pixels)
  constant LAF         : integer := 480;  --Lines/Active Frame (lines)
  constant waveHorigin : natural := 0;
  constant waveVorigin : natural := 224;
  constant waveHsize   : natural := 640;
  constant waveVsize   : natural := 256;
  
  signal   hCnt     : std_logic_vector(10 downto 0);
  signal   vCnt     : std_logic_vector(10 downto 0);
  signal   intHcnt  : integer range 0 to 800-1;  --PLD-1 - horizontal counter
  signal   intVcnt  : integer range 0 to 521-1;  -- LFD-1 - vertical counter
  signal   vgaRed   : std_logic_vector(2 downto 0);
  signal   vgaGreen : std_logic_vector(2 downto 0);
  signal   vgaBlue  : std_logic_vector(1 downto 0);
  signal   Hsync    : std_logic;
  signal   Vsync    : std_logic;

  type   fourRom is array (3 downto 0) of std_logic_vector(7 downto 0);
  signal mhzArray : fourRom := (x"00", x"00", x"00", x"00");
  signal khzArray : fourRom := (x"00", x"00", x"00", x"00");
  type   twoRom is array (1 downto 0) of std_logic_vector(7 downto 0);
  signal volArray : twoRom  := (x"00", x"00");
  signal bwsArray : twoRom  := (x"00", x"00");
  
  type   waveArray_t is array (0 to waveHsize-1) of natural range 0 to waveVsize-1;
  signal waveArray : waveArray_t;
  
  type charArray is array (0 to 79) of std_logic_vector(7 downto 0);
  -- V 0:7  , H0:639              "UART Tx     : "
  -- 52 61 64 69 6f 20 53 74 61 74 65 20 3a 20
  signal line0 : charArray := (x"55", x"41", x"52", x"54",   -- 0
                               x"20", x"54", x"78", x"00",   -- 4
                               x"00", x"00", x"00", x"00",   -- 8
                               x"3a", x"20", x"00", x"00",   -- 12
                               x"00", x"00", x"00", x"00",   -- 16
                               x"00", x"00", x"00", x"00",   -- 20
                               x"00", x"00", x"00", x"00",   -- 24
                               x"00", x"00", x"00", x"00",   -- 28
                               x"00", x"00", x"00", x"00",   -- 32
                               x"00", x"00", x"00", x"00",   -- 36
                               x"00", x"00", x"00", x"00",   -- 40
                               x"00", x"00", x"00", x"00",   -- 44
                               x"00", x"00", x"00", x"00",   -- 48
                               x"00", x"00", x"00", x"00",   -- 52
                               x"00", x"00", x"00", x"00",   -- 56
                               x"00", x"00", x"00", x"00",   -- 60
                               x"00", x"00", x"00", x"00",   -- 64
                               x"00", x"00", x"00", x"00",   -- 68
                               x"00", x"00", x"00", x"00",   -- 72
                               x"00", x"00", x"00", x"00"    -- 76
                               );
  -- V 8:15 , H0:639              "Frequency   : "
  -- 46 72 65 71 75 65 6e 63 79 20 20 20 3a
  signal line1 : charArray := (x"46", x"72", x"65", x"71",   -- 0
                               x"75", x"65", x"6e", x"63",   -- 4 
                               x"79", x"20", x"20", x"20",   -- 8
                               x"3a", x"20", x"00", x"00",   -- 12
                               x"00", x"00", x"2e", x"00",   -- 16
                               x"00", x"00", x"00", x"20",   -- 20
                               x"4d", x"48", x"7a", x"00",   -- 24
                               x"00", x"00", x"00", x"00",   -- 28
                               x"00", x"00", x"00", x"00",   -- 32
                               x"00", x"00", x"00", x"00",   -- 36
                               x"00", x"00", x"00", x"00",   -- 40
                               x"00", x"00", x"00", x"00",   -- 44
                               x"00", x"00", x"00", x"00",   -- 48
                               x"00", x"00", x"00", x"00",   -- 52
                               x"00", x"00", x"00", x"00",   -- 56
                               x"00", x"00", x"00", x"00",   -- 60
                               x"00", x"00", x"00", x"00",   -- 64
                               x"00", x"00", x"00", x"00",   -- 68
                               x"00", x"00", x"00", x"00",   -- 72
                               x"00", x"00", x"00", x"00"    -- 76
                               );
  -- V16:23 , H0:639              "Modulation  : "
  -- 4d 6f 64 75 6c 61 74 69 6f 6e 20 20 3a 20
  signal line2 : charArray := (x"4d", x"6f", x"64", x"75",
                               x"6c", x"61", x"74", x"69",
                               x"6f", x"6e", x"20", x"20",
                               x"3a", x"20", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00"
                               );
  -- V24:31 , H0:639              "Rx Out      : "
  -- 52 78 20 4f 75 74 20 20 20 20 20 20 3a 20
  signal line3 : charArray := (x"52", x"78", x"20", x"4f",
                               x"75", x"74", x"20", x"20",
                               x"20", x"20", x"20", x"20",
                               x"3a", x"20", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00"
                               );
  -- V32:39 , H0:639          "Volume      : "
  -- 566f 6c75 6d65 
  signal line4 : charArray := (x"56", x"6f", x"6c", x"75",
                               x"6d", x"65", x"20", x"20",
                               x"20", x"20", x"20", x"20",
                               x"3a", x"20", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00"
                               );
  -- V40:47 , H0:639          "BWS         : "
  -- 5361 6d70 6c65 2052 6174 6520 3a20 3738 2e31 3235 204b 5350 53
  signal line5 : charArray := (x"42", x"57", x"53", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"3a", x"20", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00"
                               );
  -- V48:56 , H0:639          "Sample Rate : 78.125 KSPS"
  -- 5361 6d70 6c65 2052 6174 6520 3a20 3738 2e31 3235 204b 5350 53
  signal line6 : charArray := (x"53", x"61", x"6d", x"70",
                               x"6c", x"65", x"20", x"52",
                               x"61", x"74", x"65", x"20",
                               x"3a", x"20", x"37", x"38",
                               x"2e", x"31", x"32", x"35",
                               x"20", x"4b", x"53", x"50",
                               x"53", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00",
                               x"00", x"00", x"00", x"00"
                               );
  -- V208:215 , H0:639              "0"..."4ms"..."8.1ms"
  signal line26 : charArray := (x"30", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"34", x"6d",  -- 36
                                x"73", x"00", x"00", x"00",  -- 40
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"38",
                                x"2e", x"31", x"6d", x"73"
                                );
  -- V216:223 , H0:639              "|"..."||"..."|"
  signal line27 : charArray := (x"7c", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"7c",  -- 36
                                x"7c", x"00", x"00", x"00",  -- 40
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"00",
                                x"00", x"00", x"00", x"7c"
                                );
  signal linePxl  : std_logic;
  signal wavePxl  : std_logic;
  signal charAddr : std_logic_vector(7 downto 0);
  signal char     : std_logic_vector(0 to 63);
  signal mhz      : std_logic_vector(13 downto 0);
  signal khz      : std_logic_vector(13 downto 0);
  signal vol      : std_logic_vector(6 downto 0);
  signal bws      : std_logic_vector(3 downto 0);
  
begin  -- architecture rtl

  -- Time the screen display for given res
  vgaTiming_U : entity work.vgaTiming
    port map (
      CLK_25MHz  => in_clk25,
      CLK_40MHz  => in_clk40,
      RESOLUTION => '0',                -- 0=640, 1=800
      RST        => in_rst,
      BLANK      => open,               -- For user, 1=pixel not in view
      HCOUNT     => hCnt,               -- 11 bits
      HS         => Hsync,
      VCOUNT     => vCnt,               -- 11 bits
      VS         => Vsync);

  -- This contains the ASCII characters.
  -- NOTE: The char's left-most bit is 0 (array is 0 to 63) for convenience of
  --       indexing pixels.
  charMap_U : entity work.charMap
    port map (
      in_charAddr => charAddr,
      out_char    => char);

  mhz <= std_logic_vector(to_unsigned(in_mhz, 14));  -- Convert the integers to
  khz <= std_logic_vector(to_unsigned(in_khz, 14));  -- slv
  vol <= std_logic_vector(to_unsigned(in_radioVol, 7));
  bws <= std_logic_vector(to_unsigned(in_radioBws, 4));
  
  -- Convert the integer inputs to BCD 
  mhzTranslate_proc : process (bws, khz, mhz, vol) is
    variable bcdMhz : std_logic_vector(bcdLen(mhz)-1 downto 0);
    variable bcdKhz : std_logic_vector(bcdLen(khz)-1 downto 0);
    variable bcdVol : std_logic_vector(bcdLen(vol)-1 downto 0);
    variable bcdBws : std_logic_vector(bcdLen(bws)-1 downto 0);
  begin  -- process mhzTranslate_proc
    bcdMhz      := to_bcd(mhz);                  -- Convert the integer to BCD
    mhzArray(0) <= x"3" & bcdMhz(3 downto 0);    -- Map to the charMap
    mhzArray(1) <= x"3" & bcdMhz(7 downto 4);    -- Map to the charMap
    mhzArray(2) <= x"3" & bcdMhz(11 downto 8);   -- Map to the charMap
    mhzArray(3) <= x"3" & bcdMhz(15 downto 12);  -- Map to the charMap
    bcdKhz      := to_bcd(khz);                  -- Convert the integer to BCD
    khzArray(0) <= x"3" & bcdKhz(3 downto 0);    -- Map to the charMap
    khzArray(1) <= x"3" & bcdKhz(7 downto 4);    -- Map to the charMap
    khzArray(2) <= x"3" & bcdKhz(11 downto 8);   -- Map to the charMap
    khzArray(3) <= x"3" & bcdKhz(15 downto 12);  -- Map to the charMap
    -- Ignore uppermost digits of bcdMhz/bcdKhz - we only need 4 digits worth
    -- Trust the user not to give us values above '9999'
    bcdVol      := to_bcd(vol);                  -- Convert the integer to BCD
    volArray(0) <= x"3" & bcdVol(3 downto 0);    -- Map to the charMap
    volArray(1) <= x"3" & bcdVol(7 downto 4);    -- Map to the charMap
    bcdBws      := to_bcd(bws);                  -- Convert the integer to BCD
    bwsArray(0) <= x"3" & bcdBws(3 downto 0);    -- Map to the charMap
    bwsArray(1) <= x"3" & bcdBws(7 downto 4);    -- Map to the charMap
  end process mhzTranslate_proc;

  -- Update the lines when new parameters come in
  updateLines_proc : process (bwsArray, in_radioDemod, in_radioOnOff,
                              in_radioOutput, khzArray, mhzArray, volArray) is
  begin  -- process updateLines_proc
    -- line0 - Radio state
    case in_radioOnOff is
      when '0' =>
        line0(14) <= x"4f";             -- "On "
        line0(15) <= x"6e";
        line0(16) <= x"00";
      when '1' =>
        line0(14) <= x"4f";             -- "Off"
        line0(15) <= x"66";
        line0(16) <= x"66";
      when others =>
        line0(14) <= x"23";
        line0(15) <= x"23";
        line0(16) <= x"23";
    end case;
    -- line1 - Frequency
    line1(14) <= mhzArray(3);
    line1(15) <= mhzArray(2);
    line1(16) <= mhzArray(1);
    line1(17) <= mhzArray(0);
      -- 18 is a decimal point
    line1(19) <= khzArray(3);
    line1(20) <= khzArray(2);
    line1(21) <= khzArray(1);
    line1(22) <= khzArray(0);
    -- line2 - Modulation
    case in_radioDemod is
      when '0' =>
        line2(14) <= x"41";             -- AM
        line2(15) <= x"4d";
      when '1' =>
        line2(14) <= x"46";             -- FM
        line2(15) <= x"4d";
      when others =>
        line2(14) <= x"23";
        line2(15) <= x"23";
    end case;
    -- line3 - Rx Out
    case in_radioOutput is
      when '0' =>
        line3(14) <= x"50";             -- Phones
        line3(15) <= x"68";
        line3(16) <= x"6f";
        line3(17) <= x"6e";
        line3(18) <= x"65";
        line3(19) <= x"73";
      when '1' =>
        line3(14) <= x"49";             -- IF    
        line3(15) <= x"46";
        line3(16) <= x"00";
        line3(17) <= x"00";
        line3(18) <= x"00";
        line3(19) <= x"00";
      when others =>
        line3(14) <= x"23";
        line3(15) <= x"23";
        line3(16) <= x"23";
        line3(17) <= x"23";
        line3(18) <= x"23";
        line3(19) <= x"23";
    end case;
    -- line4 - Volume
    line4(14) <= volArray(1);
    line4(15) <= volArray(0);
    line5(14) <= bwsArray(1);
    line5(15) <= bwsArray(0);
  end process updateLines_proc;
  
  -- Integers of the VGA controller counts
  intHcnt <= to_integer(unsigned(hCnt));
  intVcnt <= to_integer(unsigned(vCnt));

  -- Select the character column of each line array depending on the line we
  -- are currently scanning.
  columnSel_proc : process(hCnt, intHcnt, intVcnt, line0, line1, line2, line26,
                           line27, line3, line4, line5, line6)
  begin
    charAddr <= x"00";
    if intHcnt < PAL and intVcnt < LAF then  -- in the active screen
      if intVcnt < 8 then
        charAddr <= line0(to_integer(unsigned(hCnt(10 downto 3))));
      elsif intVcnt >= 16 and intVcnt < 24 then
        charAddr <= line1(to_integer(unsigned(hCnt(10 downto 3))));
      elsif intVcnt >= 32 and intVcnt < 40 then
        charAddr <= line2(to_integer(unsigned(hCnt(10 downto 3))));
      elsif intVcnt >= 48 and intVcnt < 56 then
        charAddr <= line3(to_integer(unsigned(hCnt(10 downto 3))));
      elsif intVcnt >= 64 and intVcnt < 72 then
        charAddr <= line4(to_integer(unsigned(hCnt(10 downto 3))));
      elsif intVcnt >= 80 and intVcnt < 88 then
        charAddr <= line5(to_integer(unsigned(hCnt(10 downto 3))));
      elsif intVcnt >= 96 and intVcnt < 104 then
        charAddr <= line6(to_integer(unsigned(hCnt(10 downto 3))));
      elsif intVcnt >= 208 and intVcnt < 216 then
        charAddr <= line26(to_integer(unsigned(hCnt(10 downto 3))));
      elsif intVcnt >= 216 and intVcnt < 224 then
        charAddr <= line27(to_integer(unsigned(hCnt(10 downto 3))));
      end if;
    end if;
  end process columnSel_proc;

  -- Assuming that the correct char is being output, we simply need to select
  -- which pixel to display
  pixelSel_proc : process (in_clk25, char, hCnt, vCnt) is
    variable pixelIndex : std_logic_vector(5 downto 0);
  begin  -- process pixelSel_proc
    pixelIndex := vCnt(2 downto 0) & hCnt(2 downto 0);
    linePxl    <= char(to_integer(unsigned(pixelIndex)));
  end process pixelSel_proc;

  -- Every time a new audio sample is pushed to us, shift it into the array of
  -- samples. New samples are shifted into the left, pushing everything to the
  -- right, in terms of VGA dislay.
  updateWave_proc : process (in_clk) is
  begin  -- process updateWave_proc
    if rising_edge(in_clk) then         -- rising clock edge
      if in_audioDataEn = '1' then
        waveArray(0) <= to_integer(unsigned(in_audioData));
        for ii in waveHsize-1 downto 1 loop
          waveArray(ii) <= waveArray(ii-1);
        end loop;  -- ii
      end if;
    end if;
  end process updateWave_proc;
  
  -- Mapping the waveform to part of the vga screen
  -- 640x256
  -- hIndex: 0 to 639
  -- vIndex: 224 to 479
  -- intVcntLocal maps the 224:479 index to range 0:255
  wavePixel_proc : process (hCnt, intHcnt, intVcnt, waveArray) is
    variable intVcntLocal : integer;
  begin  -- process wavePixel_proc
    wavePxl      <= '0';
    intVcntLocal := intVcnt - waveVorigin;  -- Ignore the upper portion of the screen
    if intHcnt >= waveHorigin and intHcnt < waveHorigin + waveHsize and  -- during wave
      intVcnt >= waveVorigin and intVcnt < waveVorigin + waveVsize then
      if (255 - waveArray(intHcnt)) = intVcntLocal then
        wavePxl <= '1';
      end if;
      -- Lets add some dots so we know where our waveform is centered.
      -- The vertical height is not odd, so we'll use 2 rows
      if intVcntLocal = 127 or intVcntLocal = 128 then
        if hCnt(1 downto 0) = "11" then
          wavePxl <= '1';
        end if;
      end if;
    end if;
  end process wavePixel_proc;
  
  -- Mux in the text or other display elements
  vgaMux_proc : process(in_clk25, intHcnt, intVcnt, linePxl, in_backColor, wavePxl)
  begin
    if intHcnt < PAL and intVcnt < LAF then  -- in the active screen
      -- Default to background color
      vgaRed   <= in_backColor(7 downto 5);
      vgaGreen <= in_backColor(4 downto 2);
      vgaBlue  <= in_backColor(1 downto 0);
      if intVcnt < waveVorigin then
        if linePxl = '1' then
          vgaRed   <= TEXT_COLOR(7 downto 5);
          vgaGreen <= TEXT_COLOR(4 downto 2);
          vgaBlue  <= TEXT_COLOR(1 downto 0);
        end if;
      elsif wavePxl = '1' then
        vgaRed   <= TEXT_COLOR(7 downto 5);
        vgaGreen <= TEXT_COLOR(4 downto 2);
        vgaBlue  <= TEXT_COLOR(1 downto 0);
      end if;
    else
      vgaRed   <= (others => '0');
      vgaGreen <= (others => '0');
      vgaBlue  <= (others => '0');
    end if;
  end process vgaMux_proc;
  
  out_vgaRed   <= vgaRed;
  out_vgaGreen <= vgaGreen;
  out_vgaBlue  <= vgaBlue;
  out_Hsync    <= Hsync;
  out_Vsync    <= Vsync;

end architecture rtl;
